<div class="layui-layout layui-layout-admin">
  <div class="layui-header">
    <!-- 头部区域 -->
    <ul class="layui-nav layui-layout-left" id="LAYOUT_TOP_UL">
      <li class="layui-nav-item layadmin-flexible" lay-unselect>
        <a href="javascript:;" layadmin-event="flexible" title="侧边伸缩">
          <i class="layui-icon layui-icon-shrink-right" id="LAY_app_flexible"></i>
        </a>
      </li>
      <li class="layui-nav-item" lay-unselect>
        <a href="javascript:;" layadmin-event="refresh" title="刷新">
          <i class="layui-icon layui-icon-refresh-3"></i>
        </a>
      </li>
    </ul>

    <ul class="layui-nav layui-layout-right" lay-filter="layadmin-layout-right">

      <li class="layui-nav-item layui-hide-xs" lay-unselect>
        <a href="javascript:;" layadmin-event="theme">
          <i class="layui-icon layui-icon-theme"></i>
        </a>
      </li>
      <li class="layui-nav-item layui-hide-xs" lay-unselect>
        <a href="javascript:;" layadmin-event="note">
          <i class="layui-icon layui-icon-note"></i>
        </a>
      </li>
      <li class="layui-nav-item" lay-unselect>
        <script type="text/html" template lay-url="/api/current"
        lay-done="layui.element.render('nav', 'layadmin-layout-right');">
          <a href="javascript:;">
            <cite>{{ d.data.nickName }}</cite>
          </a>
          <dl class="layui-nav-child">
            <dd><a lay-href="user/info">基本资料</a></dd>
            <dd><a lay-href="user/google">谷歌验证</a></dd>
            <dd><a lay-href="user/pwd_modify">修改密码</a></dd>
            <hr>
            <dd layadmin-event="logout" style="text-align: center;"><a>退出</a></dd>
          </dl>
        </script>
      </li>

      <li class="layui-nav-item layui-hide-xs" lay-unselect>
        <a href="javascript:;" layadmin-event="about"><i class="layui-icon layui-icon-more-vertical"></i></a>
      </li>
      <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-unselect>
        <a href="javascript:;" layadmin-event="more"><i class="layui-icon layui-icon-more-vertical"></i></a>
      </li>
    </ul>
  </div>

  <!-- 侧边菜单 -->
  <div class="layui-side layui-side-menu">
    <div class="layui-side-scroll">
      <script type="text/html" template lay-url="/api/menu"
      lay-done="layui.element.render('nav', 'layadmin-system-side-menu');" id="TPL_layout">

        <div class="layui-logo" lay-href="">
          <span>{{ layui.setter.name || 'layuiAdmin' }}</span>
        </div>

        <ul class="layui-nav layui-nav-tree" lay-shrink="all" id="LAY-system-side-menu" lay-filter="layadmin-system-side-menu">
        {{#
          var path =  layui.router().path
          ,dataName = layui.setter.response.dataName;

          layui.each(d[dataName], function(index, item){
            var hasChildren = typeof item.list === 'object' && item.list.length > 0
            ,classSelected = function(){
              var match = path[0] == item.name || (index == 0 && !path[0]) || path.join('/') == item.jump;
              if(match){
                return hasChildren ? 'layui-nav-itemed' : 'layui-this';
              }
              return '';
            }
            ,url = typeof item.jump === 'string' ? item.jump : item.name;
        }}
          <li data-name="{{ item.name || '' }}" data-jump="{{ item.jump || '' }}" class="layui-nav-item {{ classSelected() }}">
            <a href="javascript:;" {{ hasChildren ? '' : 'lay-href="'+ url +'"' }} lay-tips="{{ item.title }}" lay-direction="2">
              <i class="layui-icon {{ item.icon }}"></i>
              <cite>{{ item.title }}</cite>
            </a>
            {{# if(hasChildren){ }}
              <dl class="layui-nav-child">
              {{# layui.each(item.list, function(index2, item2){
                var hasChildren2 = typeof item2.list == 'object' && item2.list.length > 0
                ,classSelected2 = function(){
                  var match = path[0] == item.name && path[1] == item2.name;
                  if(match){
                    return hasChildren2 ? 'layui-nav-itemed' : 'layui-this';
                  }
                  return '';
                }
                ,url2 = typeof item2.jump === 'string'
                  ? item2.jump
                : [item.name, item2.name, ''].join('/');
              }}
                <dd  data-name="{{ item2.name || '' }}"  data-jump="{{ item2.jump || '' }}"
                {{ classSelected2() ? ('class="'+ classSelected2() +'"') : '' }}>
                  <a href="javascript:;" {{ hasChildren2 ? '' : 'lay-href="'+ url2 +'"' }}>{{ item2.title }}</a>
                  {{# if(hasChildren2){ }}
                    <dl class="layui-nav-child">
                      {{# layui.each(item2.list, function(index3, item3){
                        var match = path[0] == item.name && path[1] == item2.name && path[2] == item3.name
                        ,url3 = typeof item3.jump === 'string'
                          ? item3.jump
                        : [item.name, item2.name, item3.name, ''].join('/')
                      }}
                        <dd data-name="{{ item3.name || '' }}"  data-jump="{{ item3.jump || '' }}"
                        {{ match ? 'class="layui-this"' : '' }}>
                          <a href="javascript:;" lay-href="{{ url3 }}">{{ item3.title }}</a>
                        </dd>
                      {{# }); }}
                    </dl>
                  {{# } }}
                </dd>
            {{# }); }}
            </dl>
            {{# } }}
          </li>
        {{# }); }}
        </ul>
      </script>
    </div>
  </div>


  <!-- 页面标签 -->
  <script type="text/html" template lay-done="layui.element.render('nav', 'layadmin-pagetabs-nav')">
    {{# if(layui.setter.pageTabs){ }}
    <div class="layadmin-pagetabs" id="LAY_app_tabs">
      <div class="layui-icon layadmin-tabs-control layui-icon-prev" layadmin-event="leftPage"></div>
      <div class="layui-icon layadmin-tabs-control layui-icon-next" layadmin-event="rightPage"></div>
      <div class="layui-icon layadmin-tabs-control layui-icon-down">
        <ul class="layui-nav layadmin-tabs-select" lay-filter="layadmin-pagetabs-nav">
          <li class="layui-nav-item" lay-unselect>
            <a href="javascript:;"></a>
            <dl class="layui-nav-child layui-anim-fadein">
              <dd layadmin-event="closeOtherTabs"><a href="javascript:;">关闭其它标签页</a></dd>
              <dd layadmin-event="closeAllTabs"><a href="javascript:;">关闭全部标签页</a></dd>
            </dl>
          </li>
        </ul>
      </div>
      <div class="layui-tab" lay-unauto lay-allowClose="true" lay-filter="layadmin-layout-tabs">
        <ul class="layui-tab-title" id="LAY_app_tabsheader">
          <li lay-id="{{ layui.setter.entry }}"><i class="layui-icon layui-icon-home"></i></li>
        </ul>
      </div>
    </div>
    {{# } }}
  </script>


  <!-- 主体内容 -->
  <div class="layui-body" id="LAY_app_body">
    <div class="layadmin-tabsbody-item layui-show"></div>
  </div>

  <!-- 辅助元素，一般用于移动设备下遮罩 -->
  <div class="layadmin-body-shade" layadmin-event="shade"></div>

</div>

<script>

  /***
   * 引入组件, 尽量不使用：layui.config({
                        base: '/x_mgr/src/lib/',
                      });
   会存在无法退出的问题。 因为common组件没有注入成功。
   直接使用：  layui.extend({autoQueryAndPlayTask: '../lib/extend/autoQueryAndPlayTask'});  退出重新登录会存在提示组件重复的错误提示！
   最佳实践： 直接在static/x_mgr/src/index.js  注入组件。
   **/
  layui.use(['admin', 'autoQueryAndPlayTask'], function() {
    var $ = layui.$
      , admin = layui.admin
      , util = layui.util
      , autoQueryAndPlayTask = layui.autoQueryAndPlayTask;

    //查询系统配置项
    admin.req({
      type: 'get',
      url: layui.setter.baseUrl + '/layout/newOrderCount/getConfig',
      error: function(err){},
      success: function(res) {
        if (res.code == 0) { //请求成功

          //组装声音对象
          if (res.data.mgrPayOrderAllTipFlag) { //开启了【支付订单】 提醒
            autoQueryAndPlayTask.addTipsItem("payOrderCount", "支付订单", "order/pay//searchState=1", res.data.mgrPayOrderSoundFlag, "mp3/newOrderByPayOrder.mp3", 3);
          }

          if (res.data.mgrAgentpayOrderAllTipFlag) { //开启了【代付订单】 提醒
            autoQueryAndPlayTask.addTipsItem("agentpayOrderCount", "代付订单", "agentpay/agentpay_audit_record//searchState=4", res.data.mgrAgentpayOrderSoundFlag, "mp3/newOrderByAgentpayOrder.mp3", 3);
          }

          if (res.data.mgrSettOrderAllTipFlag) { //开启了【结算申请】 提醒
            autoQueryAndPlayTask.addTipsItem("settOrderCount", "结算申请", "sett/audit/", res.data.mgrSettOrderSoundFlag, "mp3/newOrderBySett.mp3", 3);
          }

          //开启轮询
          autoQueryAndPlayTask.start("/layout/newOrderCount/get", 10);

          //查询系统配置项
          admin.req({
            type: 'get',
            url: layui.setter.baseUrl + '/license/getLicInfo',
            error: function (err) {},
            success: function (res) {
              if (res.code == 0) { //请求成功

                let marqueeMsg = "";
                if(res.data.subDay <= 0){
                  marqueeMsg = "提示： 您的授权文件已过期，请及时更新新授权文件！";
                }else if(res.data.subDay <= 5){
                  marqueeMsg = "提示： 您的授权文件还剩"+res.data.subDay+"天到期，请及时更新新授权文件！";
                }

                if(marqueeMsg){
                  $("#LAYOUT_TOP_UL").append(`
					  <!-- 提示消息 -->
                      <li class="layui-nav-item" lay-unselect id="LAYOUT_TOP_SUBDAYTIPS"
                          style="background: darkorange; border-radius: 4px; width: 300px; height:30px; cursor: pointer" >
                        <span style="font-size: 16px;font-weight: bold;position: relative;bottom: 10px;"><marquee>${marqueeMsg}</marquee></span>
                      </li>
            	`);
                  $("#LAYOUT_TOP_SUBDAYTIPS").click(function(){
                    location.hash = '/user/license';
                  });

                }
              }
            }
          }, false);



        }
      }

    });

  });


</script>
